package com.eupmt.lab3.persistence.ibatis;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import java.io.Reader;

/**
 *
 * @author Administrador
 */
public class PersistenceManager {

    private static PersistenceManager instance = null;
    private SqlMapClient sqlMap = null;

    //Mètodes Autogenerats Singleton
    public static PersistenceManager getInstance() {
        if (instance == null) {
            instance = new PersistenceManager();
        }
        return instance;
    }

    private PersistenceManager() {
        String resource = "com/eupmt/lab3/persistence/ibatis/SqlMapConfig.xml";
        try {
            Reader reader = Resources.getResourceAsReader(resource);
            sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public SqlMapClient getSqlMapClient() {
        return this.sqlMap;
    }
}
